package com.artron.mediaartron.ui.fragment.center;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.artron.baselib.base.BaseStaticFragment;
import com.artron.mediaartron.R;
import com.artron.mediaartron.data.config.AppProfile;
import com.artron.mediaartron.data.entity.User;
import com.artron.mediaartron.ui.activity.GeneralActivity;
import com.artron.mediaartron.ui.helper.ThrottleFirstClickHelper;
import com.artron.mediaartron.util.RegexUtils;

import butterknife.BindView;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-11-11.
 */

public class AccountManageFragment extends BaseStaticFragment implements View.OnClickListener {

    @BindView(R.id.AccountManageFragment_fl_Platform)
    protected FrameLayout mFmPlatform;
    @BindView(R.id.AccountManageFragment_tv_phone_num)
    protected TextView mTvPhoneNum;
    @BindView(R.id.AccountManageFragment_tv_password)
    protected TextView mTvPassword;
    @BindView(R.id.AccountManageFragment_tv_phone_num_isBind)
    protected TextView mTvPhoneNumIsBind;
    @BindView(R.id.AccountManageFragment_tv_password_isSetting)
    protected TextView mTvPasswordIsSetting;
    @BindView(R.id.AccountManageFragment_tv_Platform)
    protected TextView mTvBindPlatform;

    public static AccountManageFragment newInstance() {
        Bundle args = new Bundle();
        AccountManageFragment fragment = new AccountManageFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_account_manage;
    }

    @Override
    protected void initView() {
        ThrottleFirstClickHelper.throttleFirst(mTvPassword, this);
        ThrottleFirstClickHelper.throttleFirst(mTvPhoneNum, this);

        User user = AppProfile.getUserInfo().getUser();
        String mobile = user.getMobile();
        String loginPlatform = user.getLoginPlatform();
        if (TextUtils.isEmpty(mobile)) {
            mTvPhoneNumIsBind.setText("未绑定");
            mTvPasswordIsSetting.setText("未设置");
        } else {
            mTvPhoneNumIsBind.setText("已绑定" + RegexUtils.phoneNumber(mobile));
            mTvPasswordIsSetting.setText("已设置");
        }

//        if (isSetPwd == 0||TextUtils.isEmpty(mobile)) {
//        } else {
//        }
        if (TextUtils.isEmpty(user.getLoginPlatform())) {
            mFmPlatform.setVisibility(View.GONE);
        } else {
            if ("qq".equals(loginPlatform)) {
                mTvBindPlatform.setText("QQ号");
            } else if ("sina".equals(loginPlatform)) {
                mTvBindPlatform.setText("新浪微博");
            } else if ("wechat".equals(loginPlatform)) {
                mTvBindPlatform.setText("微信号");
            } else {
                mFmPlatform.setVisibility(View.GONE);
            }
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.AccountManageFragment_tv_phone_num:
                GeneralActivity.start(mContext, GeneralActivity.BIND_PHONE, "绑定手机号");
                break;
            case R.id.AccountManageFragment_tv_password:
                GeneralActivity.start(mContext, GeneralActivity.ACCOUNT_CHANGE_PASSWORD, "更改密码");
                break;
        }
    }

    public void update() {
        initView();
    }
}
